Classifying Kaggle Digits using Logistic Regression


In [1]:
# %load logistic_sgd.py
"""
This tutorial introduces logistic regression using Theano and stochastic
gradient descent.

Logistic regression is a probabilistic, linear classifier. It is parametrized
by a weight matrix :math:`W` and a bias vector :math:`b`. Classification is
done by projecting data points onto a set of hyperplanes, the distance to
which is used to determine a class membership probability.

Mathematically, this can be written as:

.. math::
  P(Y=i|x, W,b) &= softmax_i(W x + b) \\
                &= \frac {e^{W_i x + b_i}} {\sum_j e^{W_j x + b_j}}


The output of the model or prediction is then done by taking the argmax of
the vector whose i'th element is P(Y=i|x).

.. math::

  y_{pred} = argmax_i P(Y=i|x,W,b)


This tutorial presents a stochastic gradient descent optimization method
suitable for large datasets.


References:

    - textbooks: "Pattern Recognition and Machine Learning" -
                 Christopher M. Bishop, section 4.3.2

"""
__docformat__ = 'restructedtext en'

import cPickle
import gzip
import os
import sys
import timeit

import numpy

import theano
import theano.tensor as T


class LogisticRegression(object):
    """Multi-class Logistic Regression Class

    The logistic regression is fully described by a weight matrix :math:`W`
    and bias vector :math:`b`. Classification is done by projecting data
    points onto a set of hyperplanes, the distance to which is used to
    determine a class membership probability.
    """

    def __init__(self, input, n_in, n_out):
        """ Initialize the parameters of the logistic regression

        :type input: theano.tensor.TensorType
        :param input: symbolic variable that describes the input of the
                      architecture (one minibatch)

        :type n_in: int
        :param n_in: number of input units, the dimension of the space in
                     which the datapoints lie

        :type n_out: int
        :param n_out: number of output units, the dimension of the space in
                      which the labels lie

        """
        # start-snippet-1
        # initialize with 0 the weights W as a matrix of shape (n_in, n_out)
        self.W = theano.shared(
            value=numpy.zeros(
                (n_in, n_out),
                dtype=theano.config.floatX
            ),
            name='W',
            borrow=True
        )
        # initialize the biases b as a vector of n_out 0s
        self.b = theano.shared(
            value=numpy.zeros(
                (n_out,),
                dtype=theano.config.floatX
            ),
            name='b',
            borrow=True
        )

        # symbolic expression for computing the matrix of class-membership
        # probabilities
        # Where:
        # W is a matrix where column-k represent the separation hyperplane for
        # class-k
        # x is a matrix where row-j  represents input training sample-j
        # b is a vector where element-k represent the free parameter of
        # hyperplane-k
        self.p_y_given_x = T.nnet.softmax(T.dot(input, self.W) + self.b)

        # symbolic description of how to compute prediction as class whose
        # probability is maximal
        self.y_pred = T.argmax(self.p_y_given_x, axis=1)
        # end-snippet-1

        # parameters of the model
        self.params = [self.W, self.b]

        # keep track of model input
        self.input = input

    def negative_log_likelihood(self, y):
        """Return the mean of the negative log-likelihood of the prediction
        of this model under a given target distribution.

        .. math::

            \frac{1}{|\mathcal{D}|} \mathcal{L} (\theta=\{W,b\}, \mathcal{D}) =
            \frac{1}{|\mathcal{D}|} \sum_{i=0}^{|\mathcal{D}|}
                \log(P(Y=y^{(i)}|x^{(i)}, W,b)) \\
            \ell (\theta=\{W,b\}, \mathcal{D})

        :type y: theano.tensor.TensorType
        :param y: corresponds to a vector that gives for each example the
                  correct label

        Note: we use the mean instead of the sum so that
              the learning rate is less dependent on the batch size
        """
        # start-snippet-2
        # y.shape[0] is (symbolically) the number of rows in y, i.e.,
        # number of examples (call it n) in the minibatch
        # T.arange(y.shape[0]) is a symbolic vector which will contain
        # [0,1,2,... n-1] T.log(self.p_y_given_x) is a matrix of
        # Log-Probabilities (call it LP) with one row per example and
        # one column per class LP[T.arange(y.shape[0]),y] is a vector
        # v containing [LP[0,y[0]], LP[1,y[1]], LP[2,y[2]], ...,
        # LP[n-1,y[n-1]]] and T.mean(LP[T.arange(y.shape[0]),y]) is
        # the mean (across minibatch examples) of the elements in v,
        # i.e., the mean log-likelihood across the minibatch.
        return -T.mean(T.log(self.p_y_given_x)[T.arange(y.shape[0]), y])
        # end-snippet-2

    def errors(self, y):
        """Return a float representing the number of errors in the minibatch
        over the total number of examples of the minibatch ; zero one
        loss over the size of the minibatch

        :type y: theano.tensor.TensorType
        :param y: corresponds to a vector that gives for each example the
                  correct label
        """

        # check if y has same dimension of y_pred
        if y.ndim != self.y_pred.ndim:
            raise TypeError(
                'y should have the same shape as self.y_pred',
                ('y', y.type, 'y_pred', self.y_pred.type)
            )
        # check if y is of the correct datatype
        if y.dtype.startswith('int'):
            # the T.neq operator returns a vector of 0s and 1s, where 1
            # represents a mistake in prediction
            return T.mean(T.neq(self.y_pred, y))
        else:
            raise NotImplementedError()


def load_data(dataset):
    ''' Loads the dataset

    :type dataset: string
    :param dataset: the path to the dataset (here Kaggle)
    '''

    #############
    # LOAD DATA #
    #############

    # Download the Kaggle dataset if it is not present
    data_dir, data_file = os.path.split(dataset)
    if data_dir == "" and not os.path.isfile(dataset):
        # Check if dataset is in the data directory.
        new_path = os.path.join(
            os.path.split("__file__")[0],
            "..",
            "data",
            dataset
        )
        if os.path.isfile(new_path) or data_file == 'kaggle.pkl.gz':
            dataset = new_path

    if (not os.path.isfile(dataset)) and data_file == 'kaggle.pkl.gz':
        import urllib
        origin = (
            'http://www.iro.umontreal.ca/~lisa/deep/data/kaggle/kaggle.pkl.gz'
        )
        print 'Downloading data from %s' % origin
        urllib.urlretrieve(origin, dataset)

    print '... loading data'

    # Load the dataset
    f = gzip.open(dataset, 'rb')
    train_set, valid_set, test_set = cPickle.load(f)
    f.close()
    #train_set, valid_set, test_set format: tuple(input, target)
    #input is an numpy.ndarray of 2 dimensions (a matrix)
    #witch row's correspond to an example. target is a
    #numpy.ndarray of 1 dimensions (vector)) that have the same length as
    #the number of rows in the input. It should give the target
    #target to the example with the same index in the input.

    def shared_dataset(data_xy, borrow=True):
        """ Function that loads the dataset into shared variables

        The reason we store our dataset in shared variables is to allow
        Theano to copy it into the GPU memory (when code is run on GPU).
        Since copying data into the GPU is slow, copying a minibatch everytime
        is needed (the default behaviour if the data is not in a shared
        variable) would lead to a large decrease in performance.
        """
        data_x, data_y = data_xy
        shared_x = theano.shared(numpy.asarray(data_x,
                                               dtype=theano.config.floatX),
                                 borrow=borrow)
        shared_y = theano.shared(numpy.asarray(data_y,
                                               dtype=theano.config.floatX),
                                 borrow=borrow)
        # When storing data on the GPU it has to be stored as floats
        # therefore we will store the labels as ``floatX`` as well
        # (``shared_y`` does exactly that). But during our computations
        # we need them as ints (we use labels as index, and if they are
        # floats it doesn't make sense) therefore instead of returning
        # ``shared_y`` we will have to cast it to int. This little hack
        # lets ous get around this issue
        return shared_x, T.cast(shared_y, 'int32')

    test_set_x, test_set_y = shared_dataset(test_set)
    valid_set_x, valid_set_y = shared_dataset(valid_set)
    train_set_x, train_set_y = shared_dataset(train_set)

    rval = [(train_set_x, train_set_y), (valid_set_x, valid_set_y),
            (test_set_x, test_set_y)]
    return rval


def sgd_optimization_mnist(learning_rate=0.13, n_epochs=1000,
                           dataset='kaggle.pkl.gz',
                           batch_size=600):
    """
    Demonstrate stochastic gradient descent optimization of a log-linear
    model

    This is demonstrated on Kaggle.

    :type learning_rate: float
    :param learning_rate: learning rate used (factor for the stochastic
                          gradient)

    :type n_epochs: int
    :param n_epochs: maximal number of epochs to run the optimizer

    :type dataset: string
    :param dataset: the path of the Kaggle dataset file from
                 http://www.iro.umontreal.ca/~lisa/deep/data/kaggle/kaggle.pkl.gz

    """
    datasets = load_data(dataset)

    train_set_x, train_set_y = datasets[0]
    valid_set_x, valid_set_y = datasets[1]
    test_set_x, test_set_y = datasets[2]

    # compute number of minibatches for training, validation and testing
    n_train_batches = train_set_x.get_value(borrow=True).shape[0] / batch_size
    n_valid_batches = valid_set_x.get_value(borrow=True).shape[0] / batch_size
    n_test_batches = test_set_x.get_value(borrow=True).shape[0] / batch_size

    ######################
    # BUILD ACTUAL MODEL #
    ######################
    print '... building the model'

    # allocate symbolic variables for the data
    index = T.lscalar()  # index to a [mini]batch

    # generate symbolic variables for input (x and y represent a
    # minibatch)
    x = T.matrix('x')  # data, presented as rasterized images
    y = T.ivector('y')  # labels, presented as 1D vector of [int] labels

    # construct the logistic regression class
    # Each Kaggle image has size 28*28
    classifier = LogisticRegression(input=x, n_in=28 * 28, n_out=10)

    # the cost we minimize during training is the negative log likelihood of
    # the model in symbolic format
    cost = classifier.negative_log_likelihood(y)

    # compiling a Theano function that computes the mistakes that are made by
    # the model on a minibatch
    test_model = theano.function(
        inputs=[index],
        outputs=classifier.errors(y),
        givens={
            x: test_set_x[index * batch_size: (index + 1) * batch_size],
            y: test_set_y[index * batch_size: (index + 1) * batch_size]
        }
    )

    validate_model = theano.function(
        inputs=[index],
        outputs=classifier.errors(y),
        givens={
            x: valid_set_x[index * batch_size: (index + 1) * batch_size],
            y: valid_set_y[index * batch_size: (index + 1) * batch_size]
        }
    )

    # compute the gradient of cost with respect to theta = (W,b)
    g_W = T.grad(cost=cost, wrt=classifier.W)
    g_b = T.grad(cost=cost, wrt=classifier.b)

    # start-snippet-3
    # specify how to update the parameters of the model as a list of
    # (variable, update expression) pairs.
    updates = [(classifier.W, classifier.W - learning_rate * g_W),
               (classifier.b, classifier.b - learning_rate * g_b)]

    # compiling a Theano function `train_model` that returns the cost, but in
    # the same time updates the parameter of the model based on the rules
    # defined in `updates`
    train_model = theano.function(
        inputs=[index],
        outputs=cost,
        updates=updates,
        givens={
            x: train_set_x[index * batch_size: (index + 1) * batch_size],
            y: train_set_y[index * batch_size: (index + 1) * batch_size]
        }
    )
    # end-snippet-3

    ###############
    # TRAIN MODEL #
    ###############
    print '... training the model'
    # early-stopping parameters
    patience = 5000  # look as this many examples regardless
    patience_increase = 2  # wait this much longer when a new best is
                                  # found
    improvement_threshold = 0.995  # a relative improvement of this much is
                                  # considered significant
    validation_frequency = min(n_train_batches, patience / 2)
                                  # go through this many
                                  # minibatche before checking the network
                                  # on the validation set; in this case we
                                  # check every epoch

    best_validation_loss = numpy.inf
    test_score = 0.
    start_time = timeit.default_timer()

    done_looping = False
    epoch = 0
    while (epoch < n_epochs) and (not done_looping):
        epoch = epoch + 1
        for minibatch_index in xrange(n_train_batches):

            minibatch_avg_cost = train_model(minibatch_index)
            # iteration number
            iter = (epoch - 1) * n_train_batches + minibatch_index

            if (iter + 1) % validation_frequency == 0:
                # compute zero-one loss on validation set
                validation_losses = [validate_model(i)
                                     for i in xrange(n_valid_batches)]
                this_validation_loss = numpy.mean(validation_losses)

                print(
                    'epoch %i, minibatch %i/%i, validation error %f %%' %
                    (
                        epoch,
                        minibatch_index + 1,
                        n_train_batches,
                        this_validation_loss * 100.
                    )
                )

                # if we got the best validation score until now
                if this_validation_loss < best_validation_loss:
                    #improve patience if loss improvement is good enough
                    if this_validation_loss < best_validation_loss *  \
                       improvement_threshold:
                        patience = max(patience, iter * patience_increase)

                    best_validation_loss = this_validation_loss
                    # test it on the test set

                    test_losses = [test_model(i)
                                   for i in xrange(n_test_batches)]
                    test_score = numpy.mean(test_losses)

                    print(
                        (
                            '     epoch %i, minibatch %i/%i, test error of'
                            ' best model %f %%'
                        ) %
                        (
                            epoch,
                            minibatch_index + 1,
                            n_train_batches,
                            test_score * 100.
                        )
                    )

                    # save the best model
                    with open('best_model.pkl', 'w') as f:
                        cPickle.dump(classifier, f)

            if patience <= iter:
                done_looping = True
                break

    end_time = timeit.default_timer()
    print(
        (
            'Optimization complete with best validation score of %f %%,'
            'with test performance %f %%'
        )
        % (best_validation_loss * 100., test_score * 100.)
    )
    print 'The code run for %d epochs, with %f epochs/sec' % (
        epoch, 1. * epoch / (end_time - start_time))
    print >> sys.stderr, ('The code for file ' +
                          os.path.split("__file__")[1] +
                          ' ran for %.1fs' % ((end_time - start_time)))


def predict():
    """
    An example of how to load a trained model and use it
    to predict labels.
    """

    # load the saved model
    classifier = cPickle.load(open('best_model.pkl'))

    # compile a predictor function
    predict_model = theano.function(
        inputs=[classifier.input],
        outputs=classifier.y_pred)

    # We can test it on some examples from test test
    dataset='kaggle.pkl.gz'
    datasets = load_data(dataset)
    test_set_x, test_set_y = datasets[2]
    test_set_x = test_set_x.get_value()

    predicted_values = predict_model(test_set_x[:10])
    print ("Predicted values for the first 10 examples in test set:")
    print predicted_values


# if __name__ == '__main__':
#     sgd_optimization_mnist()


Couldn't import dot_parser, loading of dot files will not be possible.
Using gpu device 0: GRID K520 (CNMeM is disabled)

In [2]:
sgd_optimization_mnist()


... loading data
... building the model
... training the model
epoch 1, minibatch 116/116, validation error 11.644928 %
     epoch 1, minibatch 116/116, test error of best model 89.789855 %
epoch 2, minibatch 116/116, validation error 10.224638 %
     epoch 2, minibatch 116/116, test error of best model 89.887681 %
epoch 3, minibatch 116/116, validation error 9.543478 %
     epoch 3, minibatch 116/116, test error of best model 89.927536 %
epoch 4, minibatch 116/116, validation error 9.217391 %
     epoch 4, minibatch 116/116, test error of best model 89.945652 %
epoch 5, minibatch 116/116, validation error 8.876812 %
     epoch 5, minibatch 116/116, test error of best model 89.956522 %
epoch 6, minibatch 116/116, validation error 8.695652 %
     epoch 6, minibatch 116/116, test error of best model 89.971014 %
epoch 7, minibatch 116/116, validation error 8.528986 %
     epoch 7, minibatch 116/116, test error of best model 89.985507 %
epoch 8, minibatch 116/116, validation error 8.369565 %
     epoch 8, minibatch 116/116, test error of best model 90.000000 %
epoch 9, minibatch 116/116, validation error 8.246377 %
     epoch 9, minibatch 116/116, test error of best model 90.010870 %
epoch 10, minibatch 116/116, validation error 8.166667 %
     epoch 10, minibatch 116/116, test error of best model 90.028986 %
epoch 11, minibatch 116/116, validation error 8.079710 %
     epoch 11, minibatch 116/116, test error of best model 90.032609 %
epoch 12, minibatch 116/116, validation error 7.985507 %
     epoch 12, minibatch 116/116, test error of best model 90.028986 %
epoch 13, minibatch 116/116, validation error 7.934783 %
     epoch 13, minibatch 116/116, test error of best model 90.025362 %
epoch 14, minibatch 116/116, validation error 7.884058 %
     epoch 14, minibatch 116/116, test error of best model 90.032609 %
epoch 15, minibatch 116/116, validation error 7.840580 %
     epoch 15, minibatch 116/116, test error of best model 90.036232 %
epoch 16, minibatch 116/116, validation error 7.789855 %
     epoch 16, minibatch 116/116, test error of best model 90.050725 %
epoch 17, minibatch 116/116, validation error 7.746377 %
     epoch 17, minibatch 116/116, test error of best model 90.057971 %
epoch 18, minibatch 116/116, validation error 7.717391 %
     epoch 18, minibatch 116/116, test error of best model 90.065217 %
epoch 19, minibatch 116/116, validation error 7.623188 %
     epoch 19, minibatch 116/116, test error of best model 90.072464 %
epoch 20, minibatch 116/116, validation error 7.594203 %
     epoch 20, minibatch 116/116, test error of best model 90.068841 %
epoch 21, minibatch 116/116, validation error 7.557971 %
     epoch 21, minibatch 116/116, test error of best model 90.068841 %
epoch 22, minibatch 116/116, validation error 7.500000 %
     epoch 22, minibatch 116/116, test error of best model 90.065217 %
epoch 23, minibatch 116/116, validation error 7.420290 %
     epoch 23, minibatch 116/116, test error of best model 90.061594 %
epoch 24, minibatch 116/116, validation error 7.376812 %
     epoch 24, minibatch 116/116, test error of best model 90.061594 %
epoch 25, minibatch 116/116, validation error 7.362319 %
     epoch 25, minibatch 116/116, test error of best model 90.061594 %
epoch 26, minibatch 116/116, validation error 7.333333 %
     epoch 26, minibatch 116/116, test error of best model 90.068841 %
epoch 27, minibatch 116/116, validation error 7.304348 %
     epoch 27, minibatch 116/116, test error of best model 90.061594 %
epoch 28, minibatch 116/116, validation error 7.297101 %
     epoch 28, minibatch 116/116, test error of best model 90.057971 %
epoch 29, minibatch 116/116, validation error 7.304348 %
epoch 30, minibatch 116/116, validation error 7.297101 %
     epoch 30, minibatch 116/116, test error of best model 90.057971 %
epoch 31, minibatch 116/116, validation error 7.282609 %
     epoch 31, minibatch 116/116, test error of best model 90.054348 %
epoch 32, minibatch 116/116, validation error 7.275362 %
     epoch 32, minibatch 116/116, test error of best model 90.050725 %
epoch 33, minibatch 116/116, validation error 7.231884 %
     epoch 33, minibatch 116/116, test error of best model 90.050725 %
epoch 34, minibatch 116/116, validation error 7.210145 %
     epoch 34, minibatch 116/116, test error of best model 90.050725 %
epoch 35, minibatch 116/116, validation error 7.195652 %
     epoch 35, minibatch 116/116, test error of best model 90.054348 %
epoch 36, minibatch 116/116, validation error 7.181159 %
     epoch 36, minibatch 116/116, test error of best model 90.054348 %
epoch 37, minibatch 116/116, validation error 7.173913 %
     epoch 37, minibatch 116/116, test error of best model 90.061594 %
epoch 38, minibatch 116/116, validation error 7.159420 %
     epoch 38, minibatch 116/116, test error of best model 90.061594 %
epoch 39, minibatch 116/116, validation error 7.144928 %
     epoch 39, minibatch 116/116, test error of best model 90.065217 %
epoch 40, minibatch 116/116, validation error 7.123188 %
     epoch 40, minibatch 116/116, test error of best model 90.065217 %
epoch 41, minibatch 116/116, validation error 7.086957 %
     epoch 41, minibatch 116/116, test error of best model 90.065217 %
epoch 42, minibatch 116/116, validation error 7.101449 %
epoch 43, minibatch 116/116, validation error 7.094203 %
epoch 44, minibatch 116/116, validation error 7.079710 %
     epoch 44, minibatch 116/116, test error of best model 90.065217 %
epoch 45, minibatch 116/116, validation error 7.065217 %
     epoch 45, minibatch 116/116, test error of best model 90.061594 %
epoch 46, minibatch 116/116, validation error 7.050725 %
     epoch 46, minibatch 116/116, test error of best model 90.068841 %
epoch 47, minibatch 116/116, validation error 7.036232 %
     epoch 47, minibatch 116/116, test error of best model 90.072464 %
epoch 48, minibatch 116/116, validation error 7.014493 %
     epoch 48, minibatch 116/116, test error of best model 90.076087 %
epoch 49, minibatch 116/116, validation error 7.036232 %
epoch 50, minibatch 116/116, validation error 7.036232 %
epoch 51, minibatch 116/116, validation error 7.028986 %
epoch 52, minibatch 116/116, validation error 7.028986 %
epoch 53, minibatch 116/116, validation error 7.021739 %
epoch 54, minibatch 116/116, validation error 7.007246 %
     epoch 54, minibatch 116/116, test error of best model 90.068841 %
epoch 55, minibatch 116/116, validation error 7.007246 %
epoch 56, minibatch 116/116, validation error 7.007246 %
epoch 57, minibatch 116/116, validation error 7.000000 %
     epoch 57, minibatch 116/116, test error of best model 90.068841 %
epoch 58, minibatch 116/116, validation error 7.000000 %
epoch 59, minibatch 116/116, validation error 6.992754 %
     epoch 59, minibatch 116/116, test error of best model 90.065217 %
epoch 60, minibatch 116/116, validation error 6.992754 %
epoch 61, minibatch 116/116, validation error 7.000000 %
epoch 62, minibatch 116/116, validation error 6.978261 %
     epoch 62, minibatch 116/116, test error of best model 90.065217 %
epoch 63, minibatch 116/116, validation error 6.942029 %
     epoch 63, minibatch 116/116, test error of best model 90.065217 %
epoch 64, minibatch 116/116, validation error 6.949275 %
epoch 65, minibatch 116/116, validation error 6.934783 %
     epoch 65, minibatch 116/116, test error of best model 90.072464 %
epoch 66, minibatch 116/116, validation error 6.913043 %
     epoch 66, minibatch 116/116, test error of best model 90.068841 %
epoch 67, minibatch 116/116, validation error 6.905797 %
     epoch 67, minibatch 116/116, test error of best model 90.068841 %
epoch 68, minibatch 116/116, validation error 6.905797 %
epoch 69, minibatch 116/116, validation error 6.898551 %
     epoch 69, minibatch 116/116, test error of best model 90.068841 %
epoch 70, minibatch 116/116, validation error 6.884058 %
     epoch 70, minibatch 116/116, test error of best model 90.072464 %
epoch 71, minibatch 116/116, validation error 6.898551 %
epoch 72, minibatch 116/116, validation error 6.884058 %
epoch 73, minibatch 116/116, validation error 6.884058 %
epoch 74, minibatch 116/116, validation error 6.869565 %
     epoch 74, minibatch 116/116, test error of best model 90.076087 %
epoch 75, minibatch 116/116, validation error 6.855072 %
     epoch 75, minibatch 116/116, test error of best model 90.072464 %
epoch 76, minibatch 116/116, validation error 6.840580 %
     epoch 76, minibatch 116/116, test error of best model 90.072464 %
epoch 77, minibatch 116/116, validation error 6.840580 %
epoch 78, minibatch 116/116, validation error 6.826087 %
     epoch 78, minibatch 116/116, test error of best model 90.072464 %
epoch 79, minibatch 116/116, validation error 6.826087 %
epoch 80, minibatch 116/116, validation error 6.818841 %
     epoch 80, minibatch 116/116, test error of best model 90.076087 %
epoch 81, minibatch 116/116, validation error 6.826087 %
epoch 82, minibatch 116/116, validation error 6.833333 %
epoch 83, minibatch 116/116, validation error 6.826087 %
epoch 84, minibatch 116/116, validation error 6.840580 %
epoch 85, minibatch 116/116, validation error 6.840580 %
epoch 86, minibatch 116/116, validation error 6.840580 %
epoch 87, minibatch 116/116, validation error 6.826087 %
epoch 88, minibatch 116/116, validation error 6.826087 %
epoch 89, minibatch 116/116, validation error 6.833333 %
epoch 90, minibatch 116/116, validation error 6.840580 %
epoch 91, minibatch 116/116, validation error 6.833333 %
epoch 92, minibatch 116/116, validation error 6.833333 %
epoch 93, minibatch 116/116, validation error 6.826087 %
epoch 94, minibatch 116/116, validation error 6.818841 %
     epoch 94, minibatch 116/116, test error of best model 90.072464 %
epoch 95, minibatch 116/116, validation error 6.811594 %
     epoch 95, minibatch 116/116, test error of best model 90.072464 %
epoch 96, minibatch 116/116, validation error 6.811594 %
epoch 97, minibatch 116/116, validation error 6.811594 %
epoch 98, minibatch 116/116, validation error 6.804348 %
     epoch 98, minibatch 116/116, test error of best model 90.072464 %
epoch 99, minibatch 116/116, validation error 6.804348 %
epoch 100, minibatch 116/116, validation error 6.804348 %
     epoch 100, minibatch 116/116, test error of best model 90.086957 %
epoch 101, minibatch 116/116, validation error 6.789855 %
     epoch 101, minibatch 116/116, test error of best model 90.086957 %
epoch 102, minibatch 116/116, validation error 6.789855 %
epoch 103, minibatch 116/116, validation error 6.789855 %
epoch 104, minibatch 116/116, validation error 6.782609 %
     epoch 104, minibatch 116/116, test error of best model 90.090580 %
epoch 105, minibatch 116/116, validation error 6.775362 %
     epoch 105, minibatch 116/116, test error of best model 90.094203 %
epoch 106, minibatch 116/116, validation error 6.753623 %
     epoch 106, minibatch 116/116, test error of best model 90.094203 %
epoch 107, minibatch 116/116, validation error 6.746377 %
     epoch 107, minibatch 116/116, test error of best model 90.094203 %
epoch 108, minibatch 116/116, validation error 6.731884 %
     epoch 108, minibatch 116/116, test error of best model 90.090580 %
epoch 109, minibatch 116/116, validation error 6.717391 %
     epoch 109, minibatch 116/116, test error of best model 90.090580 %
epoch 110, minibatch 116/116, validation error 6.717391 %
epoch 111, minibatch 116/116, validation error 6.710145 %
     epoch 111, minibatch 116/116, test error of best model 90.094203 %
epoch 112, minibatch 116/116, validation error 6.717391 %
epoch 113, minibatch 116/116, validation error 6.724638 %
epoch 114, minibatch 116/116, validation error 6.717391 %
epoch 115, minibatch 116/116, validation error 6.710145 %
epoch 116, minibatch 116/116, validation error 6.695652 %
     epoch 116, minibatch 116/116, test error of best model 90.083333 %
epoch 117, minibatch 116/116, validation error 6.702899 %
epoch 118, minibatch 116/116, validation error 6.695652 %
epoch 119, minibatch 116/116, validation error 6.702899 %
epoch 120, minibatch 116/116, validation error 6.717391 %
epoch 121, minibatch 116/116, validation error 6.724638 %
epoch 122, minibatch 116/116, validation error 6.724638 %
epoch 123, minibatch 116/116, validation error 6.724638 %
epoch 124, minibatch 116/116, validation error 6.724638 %
epoch 125, minibatch 116/116, validation error 6.724638 %
Optimization complete with best validation score of 6.695652 %,with test performance 90.083333 %
The code run for 126 epochs, with 8.421258 epochs/sec
The code for file __file__ ran for 15.0s

In [ ]: